package com.itheima.ydd.controller;

import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.SysConfig;
import com.itheima.ydd.entity.SysConfigDto;
import com.itheima.ydd.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_config")
@CrossOrigin
@Slf4j
public class SysConfigController {

    @Autowired
    private ISysConfigService sysConfigService;

    @GetMapping("/all")
    public ResultData all() {

        List<Object> list = sysConfigService.allList();

        List<Object> allData = sysConfigService.allData();

        Map<String, String> configForm = sysConfigService.configForm();

        Map<String, Object> configRules = sysConfigService.configRules();

        HashMap<String, Object> map = new HashMap<>();

        //一级map集合
        map.put("list", list);
        map.put("allData",allData);
        map.put("configForm",configForm);
        map.put("configRules",configRules);

        return ResultData.ok("", map);

    }

    @PostMapping("/update")
    public ResultData update(@RequestBody List<SysConfig> sysConfigList){
        log.info("添加数据:{}",sysConfigList.toString());
        sysConfigService.updateBatchById(sysConfigList);
        return ResultData.ok("修改成功","");
    }




}
